package top.yzhao.trackdatasystem.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.yzhao.trackdatasystem.dao.OtherDao;
import top.yzhao.trackdatasystem.service.OtherService;
import top.yzhao.trackdatasystem.utils.FileOpUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * User: zhaoyang
 * Date: 2020/3/13
 * Time: 16:42
 * Description: No Description
 */
@Service
public class OtherServiceImpl implements OtherService {
    @Autowired
    private OtherDao otherDao;

    @Override
    public List<String> getTables() {
        List<String> tablesList = otherDao.getTables();
//        int size = tablesList.size();
        for (int i = 0; i < tablesList.size(); ) {
            String tmp = tablesList.get(i);
            if(!tmp.split("-")[0].equals("GJHS")){
                tablesList.remove(i);
            }else{
                i++;
            }
        }

        return tablesList;
    }

    @Override
    public List<String> getGc() {
        String path = "/static/gcData/gcData.txt";
        return FileOpUtils.readgcTxt(path);
    }

    @Override
    public List<String> getAnomaly() {
        String path = "/static/anomaly/anomaly_score.txt";
        return FileOpUtils.readgcTxt(path);
    }

    public String[][] getErrorMatrix(int id){
        String path = "/static/error_txt/"+id+".txt";
        List<String[]> rs = FileOpUtils.readErrorTxt(path);
        String[][] matrix = new String[15*15][3];
        int k = 0;
        for (int i = 0; i < rs.size(); i++) {
            String[] tmp = rs.get(i);
            for (int j = 0; j < tmp.length; j++) {
                if(k<15*15){
                    matrix[k][0] = i+"";
                    matrix[k][1] = j+"";
                    matrix[k][2] = tmp[j];
                    k++;
                }
            }
        }
        return matrix;
    }
}
